import time
import random
import string
from django.db import models
from django.contrib.auth.models import AbstractUser

# Create your models here.

MODEL_KWARGS = {
    "blank": True,
    "null": True,
}


def random_uid(length=9):
    random.seed(int(time.time() * 1e5))
    return ''.join(
        random.choices(string.ascii_lowercase, k=length)
    )

class UidBaseModel(models.Model):
    """
    有uid的Django模型可以考虑继承
    """
    uid = models.CharField(unique=True, default=random_uid, max_length=64,
                           **MODEL_KWARGS)
    name = models.CharField(max_length=125, **MODEL_KWARGS)

    class Meta:
        abstract = True



class UserModel(UidBaseModel):
    """
    Company内的用户
    """
    phone = models.CharField(max_length=64, **MODEL_KWARGS)

    class Meta:
        verbose_name_plural = "User | 用户账号"
        db_table = "eoms_user"
